<template>
  <div class="search">
    <Card>
      <Row @keydown.enter.native="handleSearch">
        <Form
          ref="searchForm"
          :model="searchForm"
          inline
          :label-width="70"
          class="search-form"
        >
          <Form-item label="商家名称" prop="name">
            <Input
              type="text"
              v-model="searchForm.name"
              placeholder="请输入商家名称"
              clearable
              style="width: 200px"
            />
          </Form-item>
          <!-- <Form-item label="项目" prop="pro">
            <Input
              type="text"
              v-model="searchForm.pro"
              placeholder="请输入项目"
              clearable
              style="width: 200px"
            />
          </Form-item> -->
          <Button
            @click="handleSearch"
            class="search-btn"
            type="primary"
            icon="ios-search"
            >搜索</Button
          >
        </Form>
      </Row>
      <Table
        :loading="loading"
        border
        :columns="columns"
        class="mt_10"
        :data="data"
        ref="table"
      ></Table>
      <Row type="flex" justify="end" class="mt_10">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50, 100]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>
    <!-- 设置限额 -->
    <Modal
      v-model="detailFlag"
      title="设置限额"
      @on-ok="handleSubmit"
      @on-cancel="handleCancel"
    >
      <div>
        <Form ref="form" :model="form" :label-width="100">
          <FormItem label="商家">
            <span>{{ EditObj.name }}</span>
          </FormItem>
          <FormItem label="单笔资金量" prop="singleFund">
            <Input v-model="form.singleFund" type="number" />
          </FormItem>
          <FormItem label="日资金量" prop="dailyFund">
            <Input v-model="form.dailyFund" type="number" />
          </FormItem>
          <FormItem label="是否启用" prop="enableFlag">
            <i-switch size="large" v-model="form.enableFlag">
              <span slot="open">启用</span>
              <span slot="close">禁用</span>
            </i-switch>
          </FormItem>
        </Form>
      </div>
    </Modal>
  </div>
</template>

<script>
import { quotaGetList, updateQuota } from "@/api/limit.js";

export default {
  name: "limit",
  components: {},
  data() {
    return {
      loading: true, // 表单加载状态
      detailFlag: false,
      EditObj: {},
      searchForm: {
        // 请求参数
        pageNumber: 1,
        pageSize: 10,
        order: "desc",
        name: "",
        pro: "",
      },
      form: {
        singleFund: "",
        dailyFund: "",
        enableFlag: true,
      },
      columns: [
        {
          title: "商家",
          key: "name",
          tooltip: true,
        },
        {
          title: "转账路径",
          key: "transferPath",
        },
        {
          title: "出口",
          key: "export",
        },

        {
          title: "入口",
          key: "entrance",
        },
        {
          title: "名头",
          key: "renown",
        },
        {
          title: "项目",
          key: "pro",
        },
        {
          title: "单笔资金量",
          key: "singleFund",
        },
        {
          title: "日资金量",
          key: "dailyFund",
        },
        {
          title: "是否启用",
          align: "left",
          width: 100,
          render: (h, params) => {
            return h(
              "div",
              {},
              params.row.enableFlag == 0
                ? "启用"
                : params.row.enableFlag == 1
                ? "禁用"
                : ""
            );
          },
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          width: 200,
          fixed: "right",
          render: (h, params) => {
            return h(
              "div",
              {
                style: {
                  display: "flex",
                  justifyContent: "center",
                },
              },
              [
                h(
                  "Button",
                  {
                    props: {
                      type: "info",
                      size: "small",
                    },
                    style: {
                      marginRight: "5px",
                      display: this.selectedMember ? "none" : "block",
                    },
                    on: {
                      click: () => {
                        this.detail(params.row);
                      },
                    },
                  },
                  "编辑"
                ),
              ]
            );
          },
        },
      ],
      data: [], // 表单数据
      total: 0, // 表单数据总数
    };
  },
  methods: {
    // 分页 改变页码
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getData();
    },
    // 分页 改变页数
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.searchForm.pageNumber = 1;
      this.getData();
    },
    // 搜索
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getData();
    },
    //查询会员列表
    getData() {
      quotaGetList(this.searchForm).then((res) => {
        if (res.result.records) {
          this.loading = false;
          this.data = res.result.records;
          this.total = res.result.total;
        }
      });
    },
    //查看会员
    detail(row) {
      this.detailFlag = true;
      this.EditObj = { ...row };
      this.form = {
        enableFlag: row.enableFlag == "0" ? true : false,
        singleFund: row.singleFund,
        dailyFund: row.dailyFund,
      };
      // this.$router.push({ name: "member-detail", query: { id: row.id } });
    },
    handleSubmit() {
      updateQuota({
        enableFlag: this.form.enableFlag ? "0" : "1",
        singleFund: this.form.singleFund,
        dailyFund: this.form.dailyFund,
        id: this.EditObj.id,
      }).then((res) => {
        if (res.code == 200) {
          this.$Message.success("修改成功！");
          this.form = {
            enableFlag: true,
            singleFund: "",
            dailyFund: "",
          };
          this.EditObj = {};
          this.$refs.form.resetFields();
          this.getData();
        } else {
          this.$Message.error("修改失败！");
        }
      });
    },
    handleCancel() {
      this.form = {
        enableFlag: true,
        singleFund: "",
        dailyFund: "",
      };
      this.EditObj = {};
      this.$refs.form.resetFields();
    },
  },
  mounted() {
    this.getData();
  },
};
</script>
<style lang="scss" scoped>
/deep/ .ivu-table-wrapper {
  width: 100%;
}
/deep/ .ivu-card {
  width: 100%;
}
.face {
  width: 60px;
  height: 60px;
  border-radius: 50%;
}
</style>
